/*
 * Copyright (C) 2017-2021
 * All rights reserved, Designed By 深圳中科鑫智科技有限公司
 * Copyright authorization contact 18814114118
 */
package com.shop.zkmall.app;

import com.shop.zkmall.app.service.redis.CereRedisKeyService;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.annotation.MapperScans;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableAsync;

@EnableAsync(proxyTargetClass = true)
@MapperScans({@MapperScan("com.shop.zkmall.commons.dao"), @MapperScan("com.shop.zkmall.app.dao")})
@SpringBootApplication(scanBasePackages = {"com.shop.zkmall.commons.utils", "com.shop.zkmall.app", "com.shop.zkmall.commons.config", "com.shop.zkmall.commons.dao"})
public class CereshopAppApplication extends SpringBootServletInitializer implements CommandLineRunner {

	@Autowired
    private CereRedisKeyService cereRedisKeyService;

	/**
	 * 需要把web项目打成war包部署到外部tomcat运行时需要改变启动方式
	 */
	@Override  //重写configure方法，把springboot的入口给它
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
		return builder.sources(CereshopAppApplication.class);
	}

	public static void main(String[] args) {
		SpringApplication.run(CereshopAppApplication.class, args);
	}

	@Override
    public void run(String... args) throws Exception {
		try {
            //初始化Redis延时任务
            cereRedisKeyService.initializationRedis();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            System.out.println("------   app-server启动成功    ------\n");
        }
	}
}
